class_name TraitUI
extends PanelContainer

# ===============================================

@export var active: bool :
	set(value):
		active = value
		if active:
			modulate.a = 1.0
		else:
			modulate.a = 0.5


@export var trait_data: Trait :
	set(value):
		trait_data = value
		if value == null or not is_instance_valid(trait_name):
			return
		trait_icon.texture = trait_data.icon
		trait_name.text = trait_data.name

# ===============================================

@onready var trait_icon: TextureRect = $MarginContainer/VBoxContainer/HBoxContainer/TraitIconBackground/TraitIcon
@onready var active_units: Label = $MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/ActiveUnits
@onready var trait_level: RichTextLabel = $MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/TraitLevel
@onready var trait_name: Label = $MarginContainer/VBoxContainer/MarginContainer/TraitName

# ===============================================

func update(units: Array[Unit]) -> void:
	var unique_units: int = trait_data.get_unique_unit_count(units)
	active_units.text = str(unique_units)
	trait_level.text = trait_data.get_levels_bbcode(unique_units)
	active = trait_data.is_active(unique_units)
